package com.bwf.date;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Version v1.0
 * @Description: TODO
 * @Author ZHANZHONGXIN
 * @Date 2022/5/13 13:54
 * @Copyright 博为峰
 */
public class DateDemo {
    public static void main(String[] args) throws ParseException {
//        m1();
        m2();
//        Date d1 = new Date();
//        Date d2 = null;
    }

    private static void m2() throws ParseException {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        //Date-->String
        String format = dateFormat.format(new Date());
        System.out.println("format = " + format);

        //String-->Date
        String dateStr = "2022-05-13 14:14:36";
        Date date = dateFormat.parse(dateStr);
    }

    private static void m1() {
        //当前日期
        Date date = new Date();//Mon May 16 09:17:37 CST 2022
        System.out.println("date = " + date);

        //毫秒数
        long time = date.getTime();//1970 1 1
        System.out.println("time = " + time);

        //1652421697333
        Date date2 = new Date(1652421697333L);
        System.out.println("date2 = " + date2);
    }

    //2008-8-8到今天，相隔多少天
}
